package com.ssm.sfzy.controller;

import com.ssm.sfzy.constant.CommonConstant;
import com.ssm.sfzy.entity.Course;
import com.ssm.sfzy.service.CourseService;
import com.ssm.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author jitwxs
 * @date 2024年03月30日 11:13
 */
@RestController
@CrossOrigin
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping("/find")
    public Object find(
            @RequestParam(defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageSize,
            Course course
    ){
        Map<String, Object> map = courseService.findPage(pageNum, pageSize, course);
        return Result.success(map);
    }

    @GetMapping("/findById/{id}")
    public Object findById(@PathVariable Integer id){
        Course course = courseService.findById(id);
        return Result.success(course);
    }

    @PostMapping("/add")
    public Object add(@RequestBody Course course){
        courseService.add(course);
        return Result.success();
    }

    @PutMapping("/edit")
    public Object edit(@RequestBody Course course){
        courseService.edit(course);
        return Result.success();
    }

    @DeleteMapping("/remove/{id}")
    public Object remove(@PathVariable Integer id){
        courseService.remove(id);
        return Result.success();
    }

    @DeleteMapping("/removeBatch")
    public Object remove(Integer[] ids){
        courseService.removeBatch(ids);
        return Result.success();
    }

    @GetMapping("/getByTeacherId/{teacherId}")
    public Object getByTeacherId(@PathVariable Integer teacherId){
        List<Course> courseList = courseService.getByTeacherId(teacherId);

        return courseList;
    }

}
